<?php

View::setLayout('wap');
View::setContentType('text/vnd.wap.wml');

/**
 * wap - book reader
 */
class WapController extends Controller
{
	public function show()
	{
		$list	=	Book::getList();
		$this->assign('list', $list);
		$this->display();
	}
	
	public function book()
	{
		$bookid	=	Lib::get('id', 'int');
		$book	=	Book::getBook($bookid);
		if(!$book)
		{
			Show::go400("no such book");
		}
		$this->assign('book', $book);
		$this->display();
	}
	
	public function reader()
	{
		$bookid	=	Lib::get('id', 'int');
		$book	=	Book::getBook($bookid);
		if(!$book)
		{
			Show::go400("no such book");
		}
		$this->assign('book', $book);
		
		try {
			$cont	=	ReaderHelper::getChapter($book['path']);
		}catch(Exception $e){
			Show::go400($e->getMessage());
		}
		$this->assign('content',	ReaderHelper::wmlFormat($cont));
		$this->assign('page',		ReaderHelper::getPager($book['length'], $cont));
		
		$this->display();
	}
	
}

?>